package com.muqi.server.service;

import com.muqi.server.domain.bo.*;
import com.muqi.server.domain.po.*;
import com.muqi.server.mapper.*;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor

public class GenderService {
    private final GenderMapper Gender;
    private final ClassGenderMapper classGender;
    private final StatusGenderMapper statusGender;
    private final SemesterGenderMapper semesterGender;
    private final SemesterClassGenderMapper semesterClassGender;

    public GenderBO getGender() {
        GenderPO genderPO = Gender.selectOne(null);
        GenderBO genderBO = new GenderBO();
        genderBO.setMaleCount(genderPO.getMaleCount());
        genderBO.setFemaleCount(genderPO.getFemaleCount());
        genderBO.setUpdateTime(genderPO.getUpdateTime());
        return genderBO;
    }



    public GenderBO getClassGenderByClassId(Integer classId) {
        ClassGenderPO classGenderPO = classGender.selectById(classId);
        return convertClassGenderPoToBo(classGenderPO);
    }


    public List<ClassGenderBO> getAllClassGender() {
        return classGender.selectList(null).stream().map(this::convertClassGenderPoToBo).toList();
    }

    public List<StatusGenderBO> getAllStatusGender() {
        return statusGender.selectList(null).stream().map(this::convertStatusGenderPoToBo).toList();
    }

    public List<SemesterGenderBO> getAllSemesterGender() {
        return semesterGender.selectList(null).stream().map(this::convertSemesterGenderPoToBo).toList();
    }

    public List<SemesterClassGenderBO> getAllSemesterClassGender() {
        return semesterClassGender.selectList(null).stream().map(this::convertSemesterClassGenderPoToBo).toList();
    }


    private SemesterClassGenderBO convertSemesterClassGenderPoToBo (SemesterClassGenderPO semesterClassGenderPO) {
        SemesterClassGenderBO semesterClassGenderBO = new SemesterClassGenderBO();
        semesterClassGenderBO.setSemester(semesterClassGenderPO.getSemester());
        semesterClassGenderBO.setClassId(semesterClassGenderPO.getClassId());
        semesterClassGenderBO.setMaleCount(semesterClassGenderPO.getMaleCount());
        semesterClassGenderBO.setFemaleCount(semesterClassGenderPO.getFemaleCount());
        semesterClassGenderBO.setUpdateTime(semesterClassGenderPO.getUpdateTime());
        return semesterClassGenderBO;
    }

    private SemesterGenderBO convertSemesterGenderPoToBo(SemesterGenderPO semesterGenderPO) {
        SemesterGenderBO semesterGenderBO = new SemesterGenderBO();
        semesterGenderBO.setSemester(semesterGenderPO.getSemester());
        semesterGenderBO.setMaleCount(semesterGenderPO.getMaleCount());
        semesterGenderBO.setFemaleCount(semesterGenderPO.getFemaleCount());
        semesterGenderBO.setUpdateTime(semesterGenderPO.getUpdateTime());
        return semesterGenderBO;
    }

    private StatusGenderBO convertStatusGenderPoToBo(StatusGenderPO statusGenderPO) {
        StatusGenderBO statusGenderBO = new StatusGenderBO();
        statusGenderBO.setStatus(statusGenderPO.getStatus());
        statusGenderBO.setMaleCount(statusGenderPO.getMaleCount());
        statusGenderBO.setFemaleCount(statusGenderPO.getFemaleCount());
        statusGenderBO.setUpdateTime(statusGenderPO.getUpdateTime());
        return statusGenderBO;
    }

    private ClassGenderBO convertClassGenderPoToBo(ClassGenderPO classGenderPO) {
        ClassGenderBO classGenderBO = new ClassGenderBO();
        classGenderBO.setClassId(classGenderPO.getClassId());
        classGenderBO.setMaleCount(classGenderPO.getMaleCount());
        classGenderBO.setFemaleCount(classGenderPO.getFemaleCount());
        classGenderBO.setUpdateTime(classGenderPO.getUpdateTime());
        return classGenderBO;
    }



}
